package com.rs.controller;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.util.PoiPublicUtil;
import com.rs.entity.excel.StudentExcelEntity;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

/**
 * @author dehang
 * @date 2019/06/01
 */
@Controller
@RequestMapping("test")
public class TestController {



   @RequestMapping("/test")
   public String add(){
       return "test/test";
   }


   @RequestMapping("/excelTest")
   @ResponseBody
   public String test(@RequestParam("file") MultipartFile multipartFile, @RequestParam("termId") Integer termId) throws Exception {
       ImportParams params = new ImportParams();
//       params.setTitleRows(0);
//       params.setHeadRows(0);
       long start = System.currentTimeMillis();
       List<StudentExcelEntity> list = ExcelImportUtil.importExcel(multipartFile.getInputStream(), StudentExcelEntity.class, params);
       System.out.println(System.currentTimeMillis() - start);
       System.out.println(list.size());
       System.out.println(ReflectionToStringBuilder.toString(list.get(0)));

       System.err.println(termId);
       return "test/test";
   }



}
